{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "64ff6b59-fc6d-4f91-bd31-26ceb429d295",
   "metadata": {},
   "source": [
    "# Exercise: Pull Data From YahooFinance API\n",
    "\n",
    "You can't build trading models without financial data! A common source for data are APIs, which are a programmatic way to pull a lot of data from data brokers and vendors that make it available online. \n",
    "\n",
    "While many APIs will require an API key or token to identify you, you can use the [YahooFinance API](https://pypi.org/project/yfinance/) without a key for pulling simple and small amounts of historical data. \n",
    "\n",
    "Your task here is to: \n",
    "* If necessary, download the YahooFinance API Python wrapper package (called `yfinance`)\n",
    "* Use the `yfinance` package to download historical data for the last 3 years for at least 2 different stock tickers\n",
    "* Choose your favorite stocks to explore!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "07dfee7a-9774-413d-ba76-dcef337a2efd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# ! pip install yfinance #uncomment this line and run it only once to download the library"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e6a2381e-d8b9-49e0-b781-278c2075a1d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import yfinance as yf # you may need to install the package first before doing the import "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6014aebc-4423-4db5-8e60-8d6479ed452a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define some variables you'll use for pulling in data\n",
    "\n",
    "stock_ticker_1 = ''\n",
    "stock_ticker_2 = ''\n",
    "\n",
    "start_date = '' # use format YYYY-MM-DD\n",
    "end_date = ''"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d8114802-27ba-4369-8455-565e0fc5c869",
   "metadata": {},
   "source": [
    "To use the YahooFinance API, you may find it useful to look at the documentation. Below, we've started the code for you using the method called download(). \n",
    "\n",
    "To figure out what to pass in to that method, take a look at [this page of the YF API documentation](https://github.com/ranaroussi/yfinance?tab=readme-ov-file#multiple-tickers)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bf50a54f-97c0-4cf3-aa09-2add734fe790",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_stock_1 = yf.download( ... ) # replace ... inside this function with the correct parameters in order to get your data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20cb6e97-2f43-468c-bb41-53ce79e4e033",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_stock_2 = yf.download( ... ) # replace ... inside this function with the correct parameters in order to get your data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "822375f7-9f80-4836-b7e8-6692b974d4bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_stock_1.head() # check if your download worked"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "26f65543-5d16-4c85-9417-1609ca70b969",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_stock_2.head() # check if your download worked "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
